package com.smart.community.property.event;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 权限变更事件
 * 用于权限缓存刷新、权限变更监听等场景
 *
 * @author Wu.Liang
 * @since 2025-06-29
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PermissionChangeEvent {
    public enum EventType {
        USER_PERMISSION_CHANGE,
        ROLE_PERMISSION_CHANGE,
        PROPERTY_COMPANY_CHANGE,
        COMMUNITY_CHANGE,
        ALL_PERMISSION_CHANGE
    }

    private EventType eventType;
    private Long userId;
    private Long roleId;
    private Long propertyCompanyId;
    private Long communityId;

    // 静态工厂方法，兼容PermissionCacheUtils调用
    public static PermissionChangeEvent userPermissionChange(Long userId) {
        PermissionChangeEvent event = new PermissionChangeEvent();
        event.setEventType(EventType.USER_PERMISSION_CHANGE);
        event.setUserId(userId);
        return event;
    }

    public static PermissionChangeEvent rolePermissionChange(Long roleId) {
        PermissionChangeEvent event = new PermissionChangeEvent();
        event.setEventType(EventType.ROLE_PERMISSION_CHANGE);
        event.setRoleId(roleId);
        return event;
    }

    public static PermissionChangeEvent propertyCompanyChange(Long propertyCompanyId) {
        PermissionChangeEvent event = new PermissionChangeEvent();
        event.setEventType(EventType.PROPERTY_COMPANY_CHANGE);
        event.setPropertyCompanyId(propertyCompanyId);
        return event;
    }

    public static PermissionChangeEvent communityChange(Long communityId) {
        PermissionChangeEvent event = new PermissionChangeEvent();
        event.setEventType(EventType.COMMUNITY_CHANGE);
        event.setCommunityId(communityId);
        return event;
    }

    public static PermissionChangeEvent allPermissionChange() {
        PermissionChangeEvent event = new PermissionChangeEvent();
        event.setEventType(EventType.ALL_PERMISSION_CHANGE);
        return event;
    }
} 